<template>
	<view class="box">
		<view class="one">
			<view class="title">文字描述</view>
			<view class="textarea">
				<textarea v-model="content" :auto-height="true" placeholder="请输入反馈内容" maxlength="5000" />
			</view>
		</view>
		<view class="two">
			<view class="title">上传图片</view>
			<view class="upload flex">
				<view class="img" v-for="(item,index) in img_list" :key="index" @click="preImg(item.path)">
					<view class="img2 f-w">
						<image :src="item.path" mode="aspectFit"></image>
					</view>
					<view class="close f-w" @click.stop="del(index)">
						<image src="https://jw.xzsw2021.com/static/client/icon_95@2x.png" mode=""></image>
					</view>
				</view>
				<view class="demo fh-ct" @click="upload" v-if="showAdd">
					<image src="https://jw.xzsw2021.com/static/client/icon_110@2x.png" mode=""></image>
					<view>添加图片</view>
				</view>			
			</view>
		</view>
		<!--  -->
		<view class="btn">
			<view @click="submit">确认反馈</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content:'',
				id:"",
				img_list:[],//
				length:2,//允许上传图片数量
				showAdd:true,//是否显示上传按钮
				list:[],//
			}
		},
		onLoad(e) {
               this.id=e.id
		},
		methods: {
		
			// 上传
			upload(){
				this.$uploadImg(this.img_list,this.showAdd,this.length)
			},
			// 删除当前图片
			del(index){
				this.img_list.splice(index,1);
				if(this.img_list.length<this.length){
					this.showAdd=true;
				}
				console.log('删除',index);
			},
			// 图片预览
			preImg(url){
				let imgs=[];
				this.img_list.map(item=>{
					imgs.push(item.path)
				})
				uni.previewImage({
					current:url,
					urls:imgs,
					success(res) {
						
					},
					fail(err){
						console.log(err);
					}
				})
			},
			// 提交
			submit(){
				if(!this.content.trim()){
					this.$showToast('请输入反馈内容');
					return false;
				}
				if(!this.img_list.length){
					this.$showToast('请上传相关图片');
					return false;
				}
				let arr=[];
				this.img_list.map(item=>{
					arr.push(item.path);
				})
				let data={
					content:this.content,
					pic:arr,
					product_id:this.id
				}
				this.$request('user/high_price',data).then(res => {
					 if(res.status==200){
						 uni.redirectTo({
						 	url:'/pages/client/shop/question-success/question-success'
						 })
					 }
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box{
		padding: 0 30rpx 150rpx;
		.title{
			margin: 36rpx 0;
		}
		textarea{
			width: 690rpx;
			min-height: 270rpx;
			padding: 20rpx 25rpx;
			height: 271rpx;
			background: #F4F4F4;
			border-radius: 8rpx;
			box-sizing: border-box;
		}
		.two{
			margin-top: 20rpx;
			overflow: hidden;
		}
		.upload{
			flex-wrap: wrap;
			&>view{
				margin-bottom: 15rpx;
			}
			&>view:not(:nth-child(3n-2)){
				margin-left: 45rpx;
			}
			.img{
				position: relative;
				flex-shrink: 0;
				width: 200rpx;
				height: 200rpx;
				background: #F8F8F8;
				.img2{
					width: 200rpx;
					height: 200rpx;
					image{
						width: 100%;
						height: 100%;
						border-radius: 8rpx;
					}
				}
				.close{
					position: absolute;
					top: 0;
					right: 0;
					width: 40rpx;
					height: 30rpx;
					z-index: 5;
					image{
						width: 100%;
						height: 100%;
					}
				}
			}
			.demo{
				justify-content: center;
				flex-shrink: 0;
				font-size: 24rpx;
				color: #999999;
				width: 200rpx;
				height: 200rpx;
				background: #F8F8F8;
				border-radius: 8rpx;
				image{
					margin-bottom: 10rpx;
					width: 39rpx;
					height: 34rpx;
				}
			}
		}
		.btn{
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750rpx;
			height: 140rpx;
			background: #FFFFFF;
			&>view{
				 margin: 19rpx auto 20rpx;
				 width: 690rpx;
				 height: 100rpx;
				 line-height: 100rpx;
				 text-align: center;
				 color: #fff;
				 font-size: 32rpx;
				 background: linear-gradient(64deg, #2BCCA5, #22B591);
				 box-shadow: 0rpx 4rpx 6rpx 0rpx rgba(20, 187, 146, 0.4);
				 border-radius: 10rpx;
			}
		}
	}
</style>
